let n = 50;
let len = 0;
for (let i = 1; i <= n; i++) {
    len += (i + '').replace(/[^5]/g, "").length;
}
console.log(len);